package com.application.library.util;

import android.graphics.Rect;
import android.view.TouchDelegate;
import android.view.View;

/**
 * 防止用户多次连续暴力点击
 */

public class ViewClickUtil {

    private static final String TAG = "ViewClickUtil";

    /**
     * 扩大View的触摸和点击响应范围,最大不超过其父View范围
     *
     * @param view
     */
    public static void expandViewTouchDelegate(final View view) {

        ((View) view.getParent()).post(new Runnable() {
            @Override
            public void run() {
                Rect bounds = new Rect();
                view.setEnabled(true);
                view.getHitRect(bounds);

                bounds.top -= 50;
                bounds.bottom += 50;
                bounds.left -= 50;
                bounds.right += 50;

                TouchDelegate touchDelegate = new TouchDelegate(bounds, view);

                ((View) view.getParent()).setTouchDelegate(touchDelegate);
            }
        });
    }

}
